﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="/layui-v2.6.8/layui-v2.6.8/layui/css/layui.css" rel="stylesheet" />
    <script src="/lib/jquery/dist/jquery.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
    <form class="layui-form" action="" lay-filter="example">
        <div class="layui-form-item">
            <label class="layui-form-label">组织ID</label>
            <div class="layui-input-block">
                <input type="text" name="depaID" id="depaID" lay-verify="title" autocomplete="off" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">模块ID</label>
            <div class="layui-input-block">
                <input type="text" name="modID" id="modID" lay-verify="title" autocomplete="off" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">上级菜单ID</label>
            <div class="layui-input-block">
                <input type="text" name="parentID" id="parentID" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">组织名称</label>
            <div class="layui-input-block">
                <input type="text" name="depaName" id="depaName" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">主负责人</label>
            <div class="layui-input-block">
                <input type="text" name="depaperson" id="depaperson" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">主负责人电话</label>
            <div class="layui-input-block">
                <input type="text" name="depaTelphone" id="depaTelphone" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="1" title="启用" checked="">
                <input type="radio" name="status" value="0" title="禁用">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">显示排序</label>
            <div class="layui-input-block">
                <input type="text" name="sort" placeholder="" id="sort" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>


    <script src="/layui-v2.6.8/layui-v2.6.8/layui/layui.js"></script>
    
    <!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
    <script>
        //（4） 前端：浏览器请求服务器的时候，要带上JWT 就在这
        $.ajaxSetup({
            beforeSend: function (xhr) {
                if (localStorage.getItem("token") !== null) {
                    //（4） 前端：浏览器请求服务器的时候，要带上JWT
                    xhr.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem("token"));
                }
            }
        });

        layui.use(['form', 'layedit', 'laydate'], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate;


            //监听提交
            form.on('submit(demo1)', function (data) {
                console.log(data);
                $.ajax({
                    url: 'https://localhost:44398/api/DepartAPI/Upt',
                    type: 'post',
                    data: data.field,
                    success: function (d) {
                        if (d > 0) {
                            layer.msg("修改成功", { time: 2000, icon: 1 }, function () {
                                parent.location.reload();
                            })
                        }
                        else {
                            layer.msg("修改失败");
                        }
                    }
                })

                return false;
            });



            //表单取值
            layui.$('#LAY-component-form-getval').on('click', function () {
                var data = form.val('example');
                alert(JSON.stringify(data));
            });
        });

        $(function () {
            $.ajax({
                url: 'https://localhost:44398/api/DepartAPI/Fan?id='+@ViewBag.id,
                type: 'post',
                success: function (d) {
                    $("#depaID").val(@ViewBag.id);
                    $("#modID").val(d.data.modID);
                    $("#parentID").val(d.data.parentID);
                    $("#depaName").val(d.data.depaName);
                    $("#depaperson").val(d.data.depaperson);
                    $("#depaTelphone").val(d.data.depaTelphone);
                    $(".status").val(d.data.status);
                    $("#sort").val(d.data.sort);
                }
            })
        })
    </script>
</body>
</html>
